<?php
/**
 * ExtMenuBase class file
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 *          EVALUATION VERSION - NOT FOR COMMERCIAL USE OR DISTRIBUTION.
 * @version 0.7.2
 */


class ExtMenuBase extends ExtContainer
{
    private $_menu_item_class_types = array('ExtMenuBaseItem','ExtPanel','ExtColorPalette','ExtDatePicker');

    public function parseNode(ExtHTMLParserNode $node,
        ExtASTWalker $astwalker)
    {
        parent::parseNode($node, $astwalker);
        $this->parseMenuItems($node, $astwalker);
    }

    private function parseMenuItems($node,$astwalker)
    {
        $mitems = $node->findPropertyByName('menuitems');
        if(!is_null($mitems))
        {
            //$this->setMenuControl($node);
            $items=parent::parseNodeWidthTag($mitems,
                $astwalker,
                true,
                $astwalker->options,
                $this,
                $this->_menu_item_class_types);
            $this->setArrayConfig('items', $items);
            $mitems->shiftUp();
        }
    }

    private function setMenuControl($root)
    {
        foreach($root->children as $node)
        {
            $this->setMenuControl($node);
            if(!is_null($node->extctl))
            {
                $node->extctl->setJavaScriptConfig('getMenu','function(){return Ext.getCmp("'.$this->getId().'"); }');
            }
        }
    }

    public function getXType()
    {
        if($this->parent instanceof ExtMenuPanel)
            return 'menupanelmenu';
        else
            return $this->_xtype;
    }

    public function  getXClass()
    {
        if($this->parent instanceof ExtMenuPanel)
            return 'Ext.ux.MenuPanelMenu';
        else
            return $this->_xclass;
    }

}
?>
